<?php
/**
 * Answer Service
 * User: zng
 * Date: 2019/11/4
 * Time: 14:34
 */
namespace app\admin\service\questions;

use app\admin\model\questions\Opt as OptModels;

Class Opt {

    /**
     * 新增答案信息
     * @param array $data 数据包
     * @return boolean|integer
     */
    public function create(array $data, int $aid)
    {
        $list = [];
        foreach ( $data['opttitle'] as $key => $_opttitle ) {
            $list[] = [
                'aid' => $aid,
                'sequence' => $key,
                'title' => $_opttitle,
                'is_answer' => $data['is_answer'][$key]
            ];
        }
        $model = new OptModels();
        return !$model->saveAll($list)->isEmpty();
    }

    /**
     * 优惠券管理编辑
     * @param array $data
     * @param array $data
     */
    public function save(array $data)
    {
        $list = [];
        foreach ( $data['opttitle'] as $key => $_opttitle ) {
            $list[] = [
                'id' => $data['optId'][$key],
                'sequence' => $key,
                'title' => $_opttitle,
                'is_answer' => $data['is_answer'][$key]
            ];
        }
        $model = new OptModels();
        return !$model->saveAll($list)->isEmpty();
    }

}